﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Kai Patrick
 * Datum: 24.04.2008
 * Zeit: 16:12
 * 
 * Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
 */

using System;
using System.Collections.Generic;

namespace Gamadus.Core.Resources
{
	public class Settings
	{
		List<string> dontCompile;
		public Settings(params string[] keywords)
		{
			dontCompile = new List<string>(keywords);
		}
		
		Dictionary<string, Setting> settings = new Dictionary<string, Setting>();
		public object this[string key]
		{
			get
			{
				return settings[key].Value;
			}
			set
			{
				if(settings.ContainsKey(key))
					settings[key].Value = value;
				else
				{
					settings[key] = new Setting(key, value,!dontCompile.Contains(key));
				}
			}
		}
	}
	
	/// <summary>
	/// Description of Setting.
	/// </summary>
	public class Setting
	{
		string m_key;
		bool m_compile;
		object m_value;
		System.Type m_type;		
		
		public string Key
		{
			get
			{
				return m_key;
			}
		}
		
		public bool Compile
		{
			get
			{
				return m_compile;
			}
		}
		
		public object Value
		{
			get
			{
				return m_value;
			}
			set
			{
				if(value.GetType() == m_type)
					m_value = value;
				else
					throw new FormatException("Wrong type assigned to setting '"+m_key+"' (expected "+m_type.Name+")");
			}
		}
		
		public Setting(string key, object value)
		{
			m_key = key;
			m_value = value;
			m_compile = true;
			m_type = m_value.GetType();
		}
		
		public Setting(string key, object value, bool compile) : this(key, value)
		{
			m_compile = compile;
		}
		
	}
}
